"use strict";
/**
 * @bussiness {登录}
 * @author {填写作者}
 * @date {创建时间}
 * **/
const Controller = require("egg").Controller;
const { md5 } = require("../../middleware/utils/crypto")
class Login extends Controller {
    // 手机密码登录
    async loginbycellphone() {
        const { ctx, app } = this;
        const params = ctx.request.body; // 拿到参数
        const verify = ctx.session.verify; // 验证码
        const checkRes = await ctx.service.login.index.checklogin(params); // 验证结果
        if (checkRes.status && params.verify == verify) {
            /**@effect {生成tooken}*/
            const token = app.jwt.sign(
                {
                    cellphone: params.cellphone,
                },
                app.config.jwt.secret
            ); // 生成token
            checkRes.data.password = null;
            checkRes.data.cellphone = md5(checkRes.data.cellphone);
            ctx.body = {
                data: {
                    status: 200,
                    data: checkRes.data,
                    token: token, // 返回token
                },
            };
        } else if (params.verify != verify) {
            ctx.body = {
                data: {
                    status: 4013,
                    data: null,
                    msg: "验证码错误！请重新输入！",
                }
            }
        } else if (checkRes.phoneError) {
            ctx.body = {
                data: {
                    status: 4023,
                    data: null,
                    msg: "手机号错误！请检查手机号是否正确！",
                }
            }
        } else if (checkRes.NotFound) {
            ctx.body = {
                data: {
                    status: 4033,
                    data: null,
                    msg: "手机号未注册！",
                }
            };
        } else if (checkRes.psdError) {
            ctx.body = {
                data: {
                    status: 4043,
                    data: null,
                    msg: "密码错误！请重输！",
                }
            };
        } else {
            ctx.body = {
                data: {
                    status: 4053,
                    data: null,
                    msg: "手机号码或密码错误！请重输！",
                }
            };
        }
    }
}
module.exports = Login